// 定义常量作为key
const SHAREHISTORYKEY = 'SHAREHISTORYKEY'

// 保存
function saveHistory (history) {
  localStorage.setItem(SHAREHISTORYKEY, JSON.stringify(history))
}

// 读取
function getHistory () {
  // 格式 string
  const historyStr = localStorage.getItem(SHAREHISTORYKEY)
  // 如果为空 返回空数组
  const history = JSON.parse(historyStr)
  if (history) {
    return history
  } else {
    return []
  }
}

// 删除
function removeHistory () {
  localStorage.removeItem(SHAREHISTORYKEY)
}

// 暴露
export { saveHistory, getHistory, removeHistory }
